﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace det
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        Chuoiketnoi con = new Chuoiketnoi();
        Xuly xl = new Xuly();
        public static string user = string.Empty;
        public static bool Login = false;
        public Form1()
        {
            InitializeComponent();
        }
        #region Phân quyền
        // An form
        public void An()
        {
            this.btnBackup.Enabled = false;
            this.btnBaogia.Enabled = false;
            this.btnCustomer.Enabled = false;
            this.btnDondathang.Enabled = false;
            this.btnGiaohang.Enabled = false;
            this.btnIndat.Enabled = false;
            this.btnInxuat.Enabled = false;
            this.btnLogin.Enabled = true;
            this.btnLogout.Enabled = false;
            this.btnMathang.Enabled = false;
            this.btnNcc.Enabled = false;
            this.btnNhanhang.Enabled = false;
            this.btnNhapkho.Enabled = false;
            this.btnPassword.Enabled = false;
            this.btnRestore.Enabled = false;
            this.btnThoat.Enabled = true;
            this.btnTkhang.Enabled = false;
            this.btnTkHangdl.Enabled = false;
            this.btnTkno.Enabled = false;
            this.btnTktien.Enabled = false;
            this.btnTonkho.Enabled = false;
            this.btnUser.Enabled = false;
            this.btnXuatkho.Enabled = false;
        }
        // Admin
        public void admin()
        {
            this.btnBackup.Enabled = true;
            this.btnBaogia.Enabled = true;
            this.btnCustomer.Enabled = true;
            this.btnDondathang.Enabled = true;
            this.btnGiaohang.Enabled = true;
            this.btnIndat.Enabled = true;
            this.btnInxuat.Enabled = true;
            this.btnLogin.Enabled = false;
            this.btnLogout.Enabled = true;
            this.btnMathang.Enabled = true;
            this.btnNcc.Enabled = true;
            this.btnNhanhang.Enabled = true;
            this.btnNhapkho.Enabled = true;
            this.btnPassword.Enabled = true;
            this.btnRestore.Enabled = true;
            this.btnThoat.Enabled = true;
            this.btnTkhang.Enabled = true;
            this.btnTkHangdl.Enabled = true;
            this.btnTkno.Enabled = true;
            this.btnTktien.Enabled = true;
            this.btnTonkho.Enabled = true;
            this.btnUser.Enabled = true;
            this.btnXuatkho.Enabled = true;
        }
        // Nhân viên
        public void nhanvien()
        {
            this.btnBackup.Enabled = false;
            this.btnBaogia.Enabled = true;
            this.btnCustomer.Enabled = true;
            this.btnDondathang.Enabled = true;
            this.btnGiaohang.Enabled = true;
            this.btnIndat.Enabled = true;
            this.btnInxuat.Enabled = true;
            this.btnLogin.Enabled = false;
            this.btnLogout.Enabled = true;
            this.btnMathang.Enabled = true;
            this.btnNcc.Enabled = true;
            this.btnNhanhang.Enabled = true;
            this.btnNhapkho.Enabled = true;
            this.btnPassword.Enabled = true;
            this.btnRestore.Enabled = false;
            this.btnThoat.Enabled = true;
            this.btnTkhang.Enabled = true;
            this.btnTkHangdl.Enabled = true;
            this.btnTkno.Enabled = true;
            this.btnTktien.Enabled = true;
            this.btnTonkho.Enabled = true;
            this.btnUser.Enabled = false;
            this.btnXuatkho.Enabled = true;
        }
        #endregion

        #region Sự kiện đăng nhập - đăng xuất
        private void DangNhap()
        {
            if (Login == false)
            {
                
            }
        }
        private void DangXuat()
        {
            An();
            foreach(Form f in this.MdiChildren)
            {
                f.Close();
            }
        }
        #endregion
      
        #region Load form

        private void frm_Load(object sender, EventArgs e)
        {
            An();
            if (con.kiemtraketnoi() == true)
            {
                frm_Login login = new frm_Login();
                xl.Showform(login, this);
                
            }
        }

        #endregion

        private void btnThoat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void btnLogin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_Login f = new frm_Login();
            xl.Showform(f,this);
        }

        private void btnLogout_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DangXuat();
        }

        private void btnPassword_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_Doipassword f = new frm_Doipassword();
            xl.Showform(f,this);
        }
    }
}
